<template>
  <svg aria-hidden="true" :class="svgClass" v-bind="$attrs">
    <use :xlink:href="symbolName" />
  </svg>
</template>

<script lang="ts">
import { defineComponent, computed } from "vue-demi";

export default defineComponent({
  name: "SvgIcon",
  props: {
    icon: {
      type: String,
      required: true,
    },
    className: {
      type: String,
      default: "",
    },
  },
  setup(props) {
    const symbolName = computed(() => `#icon-${props.icon}`);
    const svgClass = computed(() => {
      if (props.className) {
        return `svg-icon ${props.className}`;
      }
      return "svg-icon";
    });

    return {
      symbolName,
      svgClass,
    };
  },
});
</script>

<style lang="scss" scoped>
.svg-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: -0.15em;
  overflow: hidden;
}
</style>
